/*
 * Copyright (c) 2023-2025 elsfs Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.elsfs.cloud.common.mybatis.ext.sql;

import java.util.Map;

/**
 * 可设值接口
 *
 * @param <C> 子类类型
 */
@SuppressWarnings("unchecked")
public interface Settable<C extends Settable<C>> {

  /**
   * 设置字段表达式
   *
   * @param field 字段名称
   * @param expression 表达式
   * @param args 表达式参数
   * @return 具体实现
   */
  C set(String field, String expression, Object... args);

  /**
   * 设置字段表达式
   *
   * @param field 字段枚举
   * @param expression 表达式
   * @param args 表达式参数
   * @return 具体实现
   */
  C set(Enum<?> field, String expression, Object... args);

  /**
   * 设置字段表达式
   *
   * @param condition 条件
   * @param field 字段名称
   * @param expression 表达式
   * @return 具体实现
   */
  default C set(boolean condition, String field, String expression) {
    if (condition) {
      return this.set(field, expression);
    }

    return (C) this;
  }

  /**
   * 设置字段表达式
   *
   * @param condition 条件
   * @param field 字段枚举
   * @param expression 表达式
   * @return 具体实现
   */
  default C set(boolean condition, Enum<?> field, String expression) {
    if (condition) {
      return this.set(field, expression);
    }

    return (C) this;
  }

  /**
   * 设置字段值
   *
   * @param field 字段名称
   * @param value 值
   * @return 具体实现
   */
  C setValue(String field, Object value);

  /**
   * 设置字段值
   *
   * @param field 字段枚举
   * @param value 值
   * @return 具体实现
   */
  C setValue(Enum<?> field, Object value);

  /**
   * 设置字段值
   *
   * @param condition 条件
   * @param field 字段名称
   * @param value 值
   * @return 具体实现
   */
  default C setValue(boolean condition, String field, Object value) {
    if (condition) {
      return this.setValue(field, value);
    }

    return (C) this;
  }

  /**
   * 设置字段值
   *
   * @param condition 条件
   * @param field 字段枚举
   * @param value 值
   * @return 具体实现
   */
  default C setValue(boolean condition, Enum<?> field, Object value) {
    if (condition) {
      return this.setValue(field, value);
    }

    return (C) this;
  }

  /**
   * 批量设置字段值
   *
   * @param fieldValueMap 字段值Map
   * @return 具体实现
   */
  C setValues(Map<String, Object> fieldValueMap);

  /**
   * 批量设置字段值
   *
   * @param condition 条件
   * @param fieldValueMap 字段值Map
   * @return 具体实现
   */
  default C setValues(boolean condition, Map<String, Object> fieldValueMap) {
    if (condition) {
      return this.setValues(fieldValueMap);
    }

    return (C) this;
  }

  /**
   * 批量设置字段值
   *
   * @param fieldValueMap 字段枚举值Map
   * @return 具体实现
   */
  C setValuesEnum(Map<Enum<?>, Object> fieldValueMap);

  /**
   * 批量设置字段值
   *
   * @param condition 条件
   * @param fieldValueMap 字段枚举值Map
   * @return 具体实现
   */
  default C setValuesEnum(boolean condition, Map<Enum<?>, Object> fieldValueMap) {
    if (condition) {
      return this.setValuesEnum(fieldValueMap);
    }

    return (C) this;
  }
}
